<template>
  <div>
    <h1>预约看房列表</h1>
    <!--租房信息查询-->
    <el-form :inline="true" :model="formInline" class="demo-form-inline">

      <div style="width: 210px;">
        <el-form-item label="楼盘名称">
          <el-cascader
            v-model="pcd"
            :options="optionsRegions"
            :props="prop"
            clearable
            @change="handleChange"
          />
          <el-input v-model="formInline.name" placeholder="楼盘称" />
        </el-form-item>
      </div>
      <el-form-item>
        <el-button type="primary" @click="TenancyList()">查询</el-button>
        <el-button type="primary" @click="resetForm()">清空</el-button>
      </el-form-item>
    </el-form>

    <!--列表展示-->
    <el-table
      ref="multipleTable"
      tooltip-effect="dark"
      :data="tableData"
      border
      style="width: 100%"
      @selection-change="handleSelectionChange"
    >
      <el-table-column
        type="selection"
        width="55"
      />
      <el-table-column
        prop="id"
        label="ID"
        width="280"
      />
      <el-table-column
        prop="name"
        label="楼盘名称"
        width="150"
      />
      <el-table-column
        prop="showingsName"
        label="预约人"
        width="150"
      />
      <el-table-column
        prop="showingsMobile"
        label="联系电话"
        width="150"
      />
      <el-table-column
        prop="roomName"
        label="预约房源"
        width="200"
      />
      <el-table-column
        prop="reserveTime"
        label="预约时间"
        width="200"
      />
      <el-table-column
        prop="status"
        label="预约状态"
        width="100"
      >
        <template slot-scope="scope">
          {{ scope.row.status==0?'待看房':'已看房' }}
        </template>
      </el-table-column>
    </el-table>
    <!--分页展示-->
    <el-pagination
      background
      :current-page="pageNum"
      :page-sizes="[5, 10, 15, 20]"
      :page-size="pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
    />

  </div>
</template>

<script>
export default {
  name: 'Reservation',
  data() {
    return {
      formLabelAlign: '',
      // 列表
      tableData: [],
      // 分页
      pageNum: 1,
      pageSize: 5,
      total: 0,
      // 多选框
      multipleSelection: [],
      // 查询
      formInline: {},
      pcd: [],
      optionsRegions: [],
      prop: {
        value: 'regionId',
        children: 'regions',
        label: 'regionName'
      }

    }
  },
  created() {
    this.TenancyList()
    this.regionList()
  },
  methods: {
    handleChange(value) {
      console.log(value)
      // this.pcd=value
    },
    // 三级联动
    regionList() {
      this.axios.get('http://localhost:9999/house-resource/sysRegion/regionlist').then((response) => {
        console.log(response.data)
        this.optionsRegions = response.data.obj
      })
    },
    // 列表
    TenancyList() {
      this.axios.get('http://localhost:9999/house-resource/tbRoomReservation/list', {
        params: {
          pageNum: this.pageNum,
          pageSize: this.pageSize,
          name: this.formInline.name,
          provinceSelected: this.pcd[0],
          citySelected: this.pcd[1],
          countrySelected: this.pcd[2]
        }
      }).then((response) => {
        console.log(response.data)
        this.tableData = response.data.obj.list
        this.total = response.data.obj.total
      })
    },
    // 分页
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`)
      this.pageSize = val
      this.TenancyList()
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`)
      this.pageNum = val
      this.TenancyList()
    },
    // 多选框
    handleSelectionChange(val) {
      this.multipleSelection = val
    },
    // 清空
    resetForm() {
      this.formInline = {}
    }
  }

}
</script>

